<template>
	<view class="mine container">
		<u-navbar title-color="#fff" back-icon-color="#333333" :is-fixed="false" :is-back="false">
			<view class="header">
				<image class="setting" src="../../../static/tabbar/my/set.png" mode="" @tap="toSetting"></image>
			</view>
		</u-navbar>
		<view class="home-content-top">
			<u-avatar :src="userInfo.face" mode="circle" size="110" class="mr-30" @click="toPersonalCenter"></u-avatar>
			<view class="home-content-top-right">
				<view class="right-title mb-20">
					{{userInfo.realName || userInfo.username || '昵称'}}
				</view>
				<view class="right-subtitle mb-40">
					{{userInfo.siteName || '--'}}
				</view>
				<!-- <view class="right-desc">
					<view class="">
						<view class="right-desc-num">
							{{statistics.collectSum || '--'}}
						</view>
						<view class="">
							关注
						</view>
					</view>
					<view class="">
						<view class="right-desc-num">
							{{userInfo.expertStatistics ? userInfo.expertStatistics.collectSum : '--'}}
						</view>
						<view class="">
							收藏
						</view>
					</view>
					<view class="">
						<view class="right-desc-num">
							{{statistics.likedSum || '--'}}
						</view>
						<view class="">
							获赞
						</view>
					</view>
				</view> -->
			</view>
		</view>
		<view class="main">
			<view class="navs">
				<view class="title">
					<view class="word">
						功能与服务
					</view>
				</view>
				<view class="status">
					<view class="status-items" v-for="(item,index) in statueList" :key="item.word" @click="goto(item.url)">
						<image class="img" :src="item.imgUrl" mode=""></image>
						<view class="word">{{item.word}}</view>
					</view>
				</view>
			</view>
		</view>
		<authenModal  v-show="isShow" @close="closeBtn" @confirm="confirm" ></authenModal>
	</view>
</template>

<script>
	// import { API } from '@/config/myApi.js';
	import authenModal from "@/myComponents/modal/authen-modal.vue";
	import storage from "@/utils/storage.js";
	import api from "@/config/api.js";
	import { TYPES, EVENT } from "@/js_sdk/tim/tim-js";
	export default {
		components:{
			authenModal,
		},
		data() {
			return {
				// statistics: this.$store.state.expertStatistics,// 专家统计
				isShow:false,// 模态框
				statueList: [
					{
						imgUrl: '../../../static/tabbar/my/m-nav1.png',
						word: '我的问诊',
						url:'/pages/mine/myConsultation/index'
					},
					{
						imgUrl: '../../../static/tabbar/my/m-nav2.png',
						word: '我的挂号',
						url:'/pages/mine/myRegister/index'
					},
					{
						imgUrl: '../../../static/tabbar/my/m-nav3.png',
						word: '我的课程',
						url:'/pages/mine/course/index'
					},
					{
						imgUrl: '../../../static/tabbar/my/m-nav4.png',
						word: '我的直播',
						url:'/pages/mine/live/index'
					},{
						imgUrl: '../../../static/tabbar/my/m-nav5.png',
						word: '我的知识',
						url:'/pages/mine/knowledge/index'
					},
					{
						imgUrl: '../../../static/tabbar/my/m-nav6.png',
						word: '收益管理',
						url:'/pages/mine/deposit/index'
					},
					{
						imgUrl: '../../../static/tabbar/my/m-nav7.png',
						word: '我的评价',
						url:'/pages/mine/evaluate/index'
					},
					{
						imgUrl: '../../../static/tabbar/my/m-nav8.png',
						word: '我的动态',
						url:'/pages/mine/dynamic/index'
					}
				]
			};
		},
		computed: {
			userInfo: {
				get() {
					return  this.$store.state.userInfo; // 专家个人信息
				},
				set() {
					
				}
			},
			workbenchData: {
				get() {
					return  this.$store.state.workbenchData; // 工作台数据
				},
				set() {
					
				}
			}
		},
		mounted() {
			this.imLogin()
			uni.$on("toBack",val=> {
				if(val){
					this.getData()
				}
			})
		},
		methods: {
			imLogin:function(){
				uni.request({
					url: api.buyer + "/order/userConsult/createIMAccount",
					header: {
						'content-type': 'application/json',
						'accessToken': storage.getAccessToken(),
						'refreshToken': storage.getRefreshToken()
					},
					success: ({ data }) => {
						if (!data.result) return;
						const { id: userID, userSig } = data.result;
						this.$tim.login({ userID, userSig });
						this.$tim.on(EVENT.SDK_READY, () => {
							if (this.messages.list.length) return;
							this.messages.list.length || this.getMessageList({ isInit: true });
						});
						this.$tim.on(EVENT.MESSAGE_RECEIVED, ({ data }) => {
							this.messages.list.push(...data);
						});
					}
				});
			},
			getData() {
				if(!this.userInfo.nickName){
					this.$store.dispatch('A_userInfo')
				}
				this.userInfo = storage.getUserInfo() || this.$store.state.userInfo
			},
			// 是否认证
			isAuthen(callback,status){
				if (this.userInfo.qualification == 0) { // 0未审核，1已审核，2已拒绝，3收钱，4审核中
					this.isShow = true;
					return
				} else {
					this.isShow = false;
				}
				if(this.userInfo.qualification == 4 && status){
					uni.showToast({
						title:"正在审核中，请通过后再使用",
						icon:"none"
					})
					return
				}else{
					callback()
				}
			},
			goto(url) {
				this.isAuthen(
				()=>{
					uni.navigateTo({
						url: url
					})
				},true)
			},
			toPersonalCenter(){
				this.isAuthen(()=>{
					uni.navigateTo({
						url:"/pages/tabbar/user/personalCenter/personalInformation"
					})
				},true)
			},
			toSetting(){
					uni.navigateTo({
						url:"/pages/mine/setting/index"
					})
			},
			// 关闭模态框
			closeBtn(){
				this.isShow = false;
			},
			// 去认证
			confirm(v) {
				this.isShow = false;
				uni.navigateTo({
					url: "/pages/passport/authen", 
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './my.scss';
	
		
</style>
